import { createRouter, createWebHistory } from 'vue-router'
import HomeView from '../views/HomeView.vue'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      name: 'home',
      meta: {
        keep: false,
        isLogin: true
      },
      component: HomeView,
      children: [
        {
          path: '/one-path',
          name: 'onePath',
          meta: {
            keep: true,
            isLogin: true
          },
          component: () => import('../views/OnePathView.vue')
        },
        {
          path: '/two-path',
          name: 'twoPath',
          meta: {
            keep: true,
            isLogin: true
          },
          component: () => import('../views/TwoPathView.vue')
        },
        {
          path: '/three-path',
          name: 'threePath',
          meta: {
            keep: true,
            isLogin: true
          },
          component: () => import('../views/ThreePathView3.vue')
        },
        {
          path: '/four-path',
          name: 'fourPath',
          meta: {
            keep: true,
            isLogin: true
          },
          component: () => import('../views/FourPathView2.vue')
        }
      ]
    },
    {
      path: '/login',
      name: 'login',
      meta: {
        keep: true,
        isLogin: false
      },
      component: () => import('../views/LoginView.vue')
    },
    {
      path: '/whats-job',
      name: 'whatsJob',
      meta: {
        keep: false,
        isLogin: true
      },
      component: () => import('../views/WhatsjobView.vue')
    },
    {
      path: '/all-job',
      name: 'allJob',
      meta: {
        keep: false,
        isLogin: true
      },
      component: () => import('../views/AllJobView.vue')
    },
    {
      path: '/edit',
      name: 'edit',
      meta: {
        keep: true,
        isLogin: true
      },
      component: () => import('../views/FourPathView.vue')
    },
    {
      path: '/teacher',
      name: 'teahcer',
      meta: {
        keep: true,
        isLogin: true
      },
      component: () => import('../views/TeacherView.vue')
    }
    // {
    //   path: '/about',
    //   name: 'about',
    //   // route level code-splitting
    //   // this generates a separate chunk (About.[hash].js) for this route
    //   // which is lazy-loaded when the route is visited.
    //   component: () => import('../views/AboutView.vue')
    // }
  ]
})

router.beforeEach((to, from, next)=> {
  let token = localStorage.getItem("token")

  if(token || to.path === "/login") {
    next()
  }else {
    next("/login")
  }
})

export default router
